package com.ucpaas.sms.service.smsAudit;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jsmsframework.middleware.entity.JsmsMiddlewareConfigure;
import com.jsmsframework.middleware.entity.JsmsMqConfigure;
import com.ucpaas.sms.util.rest.utils.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class AudtiResultMQConfiguration {

    private static Logger logger = LoggerFactory.getLogger(AudtiResultMQConfiguration.class);


    String ip ;
    Integer port ;
    String username ;
    String password ;
    String queueName ;

    String mqExchange ;
    String mqRoutingkey ;
    String virtualHost = "/";

    @JsonIgnore
    String toString ;

    public AudtiResultMQConfiguration(Map<String, Object> mqMap) {
        logger.debug("查询数据库MQ信息: mqMap={}", com.jsmsframework.common.util.JsonUtil.toJson(mqMap));
        if(mqMap==null)
            throw  new IllegalArgumentException("存放审核结果的MQ配置错误");
        this.ip = (String) mqMap.get("ip");
        this.port = Integer.valueOf(mqMap.get("port").toString());
        this.username = (String) mqMap.get("username");//"jsms_admin";
        this.password = (String) mqMap.get("password");//"jsms_admin";
        this.queueName = (String) mqMap.get("queueName");//"QUEUE_OYLX_1";

        this.mqExchange = (String) mqMap.get("mqExchange");//"EXCHANGE_OYLX_1";
        this.mqRoutingkey = (String) mqMap.get("mqRoutingkey");//"ROUTINGKEY_OYLX_1";
        this.virtualHost = "/";
    }

    public AudtiResultMQConfiguration(JsmsMiddlewareConfigure jsmsMiddlewareConfigure, JsmsMqConfigure jsmsMqConfigure) {
        logger.debug("查询数据库MQ信息: jsmsMiddlewareConfigure={},jsmsMqConfigure={}", com.jsmsframework.common.util.JsonUtil.toJson(jsmsMiddlewareConfigure), com.jsmsframework.common.util.JsonUtil.toJson(jsmsMqConfigure));
        if(jsmsMiddlewareConfigure==null||jsmsMqConfigure==null)
            throw  new IllegalArgumentException("存放审核结果的MQ配置错误");
        this.ip = jsmsMiddlewareConfigure.getHostIp();
        this.port = Integer.valueOf(jsmsMiddlewareConfigure.getPort());
        this.username = jsmsMiddlewareConfigure.getUserName();//"jsms_admin";
        this.password = jsmsMiddlewareConfigure.getPassWord();//"jsms_admin";
        this.queueName = jsmsMqConfigure.getMqQueue();//"QUEUE_OYLX_1";

        this.mqExchange = jsmsMqConfigure.getMqExchange();//"EXCHANGE_OYLX_1";
        this.mqRoutingkey = jsmsMqConfigure.getMqRoutingkey();//"ROUTINGKEY_OYLX_1";
        this.virtualHost = "/";

    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getQueueName() {
        return queueName;
    }

    public void setQueueName(String queueName) {
        this.queueName = queueName;
    }

    public String getMqExchange() {
        return mqExchange;
    }

    public void setMqExchange(String mqExchange) {
        this.mqExchange = mqExchange;
    }

    public String getMqRoutingkey() {
        return mqRoutingkey;
    }

    public void setMqRoutingkey(String mqRoutingkey) {
        this.mqRoutingkey = mqRoutingkey;
    }

    public String getVirtualHost() {
        return virtualHost;
    }

    public void setVirtualHost(String virtualHost) {
        this.virtualHost = virtualHost;
    }

    @Override
    public String toString() {
        if(toString==null){
            toString = com.jsmsframework.common.util.JsonUtil.toJson(this);
        }
        return toString;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AudtiResultMQConfiguration that = (AudtiResultMQConfiguration) o;

        if (ip != null ? !ip.equals(that.ip) : that.ip != null) return false;
        if (port != null ? !port.equals(that.port) : that.port != null) return false;
        if (username != null ? !username.equals(that.username) : that.username != null) return false;
        if (password != null ? !password.equals(that.password) : that.password != null) return false;
        if (queueName != null ? !queueName.equals(that.queueName) : that.queueName != null) return false;
        if (mqExchange != null ? !mqExchange.equals(that.mqExchange) : that.mqExchange != null) return false;
        if (mqRoutingkey != null ? !mqRoutingkey.equals(that.mqRoutingkey) : that.mqRoutingkey != null) return false;
        return virtualHost != null ? virtualHost.equals(that.virtualHost) : that.virtualHost == null;
    }

    @Override
    public int hashCode() {
        int result = port != null ? port.hashCode() : 0;
        result = 31 * result + (ip != null ? ip.hashCode() : 0);
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (queueName != null ? queueName.hashCode() : 0);
        result = 31 * result + (mqExchange != null ? mqExchange.hashCode() : 0);
        result = 31 * result + (mqRoutingkey != null ? mqRoutingkey.hashCode() : 0);
        result = 31 * result + (virtualHost != null ? virtualHost.hashCode() : 0);
        return result;
    }
}
